package com.zh.note.huawei.onehundred.快递货车快递运输;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            // String weightsString = scanner.nextLine();
            String weightsString = "5,10,2,11";
            // int capacity = scanner.nextInt();
            int capacity = 20;
            solveMethod(weightsString, capacity);
        }
    }

    private static void solveMethod(String weightsString, int capacity) {
        int[] weights = Arrays.stream(weightsString.split(","))
                .mapToInt(Integer::parseInt)
                .sorted()
                .toArray();

        int totalWeight = 0;
        int index = 0;
        while (index < weights.length && totalWeight + weights[index] <= capacity) {
            totalWeight += weights[index++];
        }
        System.out.println(index);
    }
}


